<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>百度收录查询</title>
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
    <link href="css/ui.css" rel="stylesheet" type="text/css" />
	<link href="css/TableTools.css" rel="stylesheet" type="text/css" />
     <script type="text/javascript" language="javascript" src="js/jquery-1.7.1.min.js"></script>
     <script type="text/javascript" charset="utf-8" src="js/ZeroClipboard.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/TableTools.js"></script>
</head>

<body>
    <h1 class="tit">百度收录查询</h1>
    <div class="enterbox">
        <textarea id="TextBox1" ></textarea>
    </div>
    <div class="set_speed">设置查询速度<input type="text" value="3" />秒/个</div>
    <div class="sub_btn">		
        <a href="javascript: testGG()" >提交</a>
    </div>
    <div class="resutl_tit">查询结果：</div>
    <div id="maindiv">
        <div id="div3" style="width: 750px;">
            <!--<a href="javascript:void(0);" title="点击重新查询">
            <img src="image/rst.gif"></a>
        <span id="rehome">←重新查询</span>
        -->
        <div   id="div_export"></div> 
    <div id="div4">
        <span id="num_total">总:</span>
        <span id="num_total2">0</span>
        <span id="num_sl">收录:</span>
        <span id="num_sl2">0</span>
        <span id="num_nosl">未收录:</span>
        <span id="num_nosl2">0</span>
        <span id="percent">收录率:</span>
        <span id="num_pct"></span>
    </div>
</div>
<table class="tb1" id="excel_init">
    <colgroup>
    <col id="col1">
    <col id="col2" />
    <col id="col3" />
    <col id="col4" />
    <col id="col5" />
</colgroup>
<thead id="thead">
    <tr>
        <th scope="col">
            <span>No.</span>
        </th>
        <th scope="col">
            <span>标题</span>
        </th>
        <th scope="col">
            <span>网址</span>
        </th>
        <th scope="col" class="th2">
            <div id="div5">
                <img src="image/sort.gif" id="s1"></div>
            <span id="sp">收录</span>
        </th>
        <th style="border-bottom:1px solid #a5a5a5;border-right:1px solid #a5a5a5" scope="col" class="kz">
            <span>快照</span>
        </th>
    </tr>
</thead>
</table>
</div>
<script type="text/javascript">
            var count = {
                total:0,
                time : '',
                url_list:"",
                sec:3,
                star:0
            };
            function get_rs(url, num){
                var url =url;
                var num =num;
                $.ajax({
                    url: "rs.php?site="+url+"&time="+ new Date().getTime(),
                    dataType:"json",
                    success: function(data){
                        var title = $("#tr"+num).find(".title");
                        var rs = $("#tr"+num).find(".yo div");
                        var kz = $("#tr"+num).find(".kz div");
                        if(!data) {
                            title.html("数据异常");
                            console.log("data:"+data)
                            return;
                        }
                        if(data.error == 1){
                            title.html(data.title);      
                            rs.attr("class","iconwarn");
                            rs.html("no-rs");
                            kz.attr("class","");
                            kz.html("-"); 
                        }
                        if(data.error == 0){
                            title.html(data.title);      
                            rs.attr("class","iconok");
                            kz.attr("class","");
                            kz.html(data.date); 
                        }
                        $("#num_sl2").html($(".yo .iconok").length);
                        $("#num_nosl2").html($(".yo .iconwarn").length);
                        var per =  Math.floor(($(".yo .iconok").length/count.total)*100)
                        $("#num_pct").html(per+"%")
                    },
                    error:function(){
                    
                    }
                });
            }

            function testGG(){
                //清除旧数据
                $(".tb1 tbody tr").remove();
                clearInterval(count.time);
                var per = $(".set_speed input").val();
                if(per>0){
                    per = parseInt(per);
                }else{
                    per = 3
                };
                count = {
                    total:0,
                    time : '',
                    url_list:"",
                    sec:per,
                    star:0
                };
                $("#num_total2").html("0");
                $("#num_sl2").html("0");
                $("#num_nosl2").html("0"); 
                $("#num_pct").html("");
            
                var txt = document.getElementById("TextBox1");
                count.url_list = txt.value.split("\n");
                count.total = count.total + count.url_list.length;
                $("#num_total2").html(count.total);
                count.time =  setInterval(function(){
                    run();
                }, count.sec*1000);//3秒执行一次，防止百度屏蔽攻击
            }
            function run(){
                var len = count.url_list.length;
                if(count.star < len){
                    var order =  (count.star%2==0?"odd1":"odd");
                    var url = $.trim(count.url_list[count.star]);
                    url = url.substr(0,7).toLowerCase()=="http://"?url:"http://"+url;
                    var str = '';
                    str = '<tr class="'+order+'" id="tr'+count.star+'"> <td class="num">'+(count.star+1)+'</td><td class="title">-</td><td class="url2"><a href="'+url+'" target="_blank">'+url+'</a></td><td class="yo"><div class="iconloading"></div></td><td class="kz" style="border:1px;"><div class="iconloading"></div></td></tr>';
                    $(".tb1").append(str);                                                 
                    get_rs(url,count.star);
                    count.star++;
                }else{
                    clearInterval(count.time);
                }
            
            } 
$("#div_export").click(function(){
    $('#excel_init').dataTable( {
          "sDom": 'T<"clear">lfrtip',
          bPaginate:false,
          bFilter:false,
          bInfo:false,
          "oTableTools": {
            "sSwfPath": "js/copy_csv_xls_pdf.swf",
            "aButtons": [
              "xls"
            ]
          }
        } );
});
    
                 
        </script></body>
</html>